<template>
  <n-form>
    <n-form-item label="标题">
      <n-input v-model:value="addArticle.title" placeholder="请输入标题" />
    </n-form-item>
    <n-form-item label="分类">
      <n-select
        v-model:value="addArticle.categoryId"
        :options="categortyOptions"
        placeholder="请选择分类"
      />
    </n-form-item>
    <n-form-item label="内容">
      <rich-text-editor v-model="addArticle.content"></rich-text-editor>
    </n-form-item>
    <n-form-item label="">
      <n-button @click="add">提交</n-button>
    </n-form-item>
  </n-form>
</template>
<script setup>
import RichTextEditor from "@/components/RichTextEditor.vue";
import { ref, onMounted, reactive, inject } from "vue";
const axios = inject("axios");
const message = inject("message");

defineProps({
  categortyOptions: {
    type: Array,
    default: () => [],
  },
});

//文章添加数据
const addArticle = reactive({
  categoryId: null,
  title: "",
  content: "",
});

// 添加文章
const add = async () => {
  let res = await axios.post("/blog/_token/add", addArticle);
  if (res.data.code == 200) {
    message.info(res.data.msg);
  } else {
    message.error(res.data.msg);
  }
};
</script>
<style lang="scss"></style>
